﻿using StandardManager.DB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Jixiao.ListInfo
{
    internal class ProjectRadio
    {
        public static Dictionary<string, int> GetProjectRadio( string UserName, List<string> projectNames)
        {
            var conn = Form1.Connection;

            var dt = conn.SelectData("select * from ProjectRadio where userName='" + UserName + "'");
            Dictionary<string, int> pr = new Dictionary<string, int>();
            conn.Dispose();

            int radioSum = 0;
            for (var i = 0; i < dt.Rows.Count; i++)
            {
                var radio = int.Parse(dt.Rows[i]["Radio"].ToString());
                pr.Add(dt.Rows[i]["ProjectName"].ToString(), radio);

                radioSum += radio;
            }
            if (radioSum == 70)
            {
                return pr;
            }
            var leftRadio = 70 - radioSum;
            var leftCount = projectNames.Count - dt.Rows.Count;
            if (projectNames.Contains("日常工作")) { leftCount--; }
            if (projectNames.Contains("协同工作")) { leftCount--; }
            if(leftCount==0) { return pr; }

            for(var i = 0; i < projectNames.Count; i++)
            {
                if (projectNames[i].Contains("日常工作")) { continue; }
                if (projectNames[i].Contains("协同工作")) { continue; }
                if (pr.ContainsKey(projectNames[i])) continue;

                pr.Add(projectNames[i], leftRadio/ leftCount);
            }

            return pr;
        }
    }
}
